using System.Collections;
using System.Collections.Generic;
using Opc.Ua;

namespace HslCommunicationEx.OpcUa
{
	public class EventFields
	{
		private readonly EventFieldConfigurationCollection m_StandardFields;

		private EventFieldConfigurationCollection m_AdditionalFields;

		private readonly Hashtable m_MapStandardFieldIndex = new Hashtable();

		public EventFieldConfigurationCollection StandardFields => this.m_StandardFields;

		public EventFieldConfigurationCollection AdditionalFields
		{
			get
			{
				return this.m_AdditionalFields;
			}
			set
			{
				this.m_AdditionalFields = value;
			}
		}

		public EventFields()
		{
			this.m_StandardFields = new EventFieldConfigurationCollection();
			this.m_AdditionalFields = new EventFieldConfigurationCollection();
			this.AddEventField(ObjectTypeIds.BaseEventType, "EventId", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "EventType", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "SourceNode", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "SourceName", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "Time", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "ReceiveTime", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "Message", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "Severity", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "", 1u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "ConditionName", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "Retain", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "AckedState", 13u);
			this.AddEventField(ObjectTypeIds.BaseEventType, "ActiveState", 13u);
			List<QualifiedName> browsePath = new List<QualifiedName> { "AckedState", "Id" };
			this.AddEventField(ObjectTypeIds.BaseEventType, browsePath, 13u);
			browsePath = new List<QualifiedName> { "ActiveState", "Id" };
			this.AddEventField(ObjectTypeIds.BaseEventType, browsePath, 13u);
		}

		public int getIndexForEventField(string browseName)
		{
			List<QualifiedName> list = new List<QualifiedName>();
			if (browseName.Length != 0)
			{
				list.Add(browseName);
			}
			return this.getIndexForEventField(list);
		}

		public int getIndexForEventField(List<QualifiedName> browsePath)
		{
			string text = "";
			for (int i = 0; i < browsePath.Count; i++)
			{
				text += browsePath[0].Name;
				if (i + 1 < browsePath.Count)
				{
					text += "/";
				}
			}
			if (this.m_MapStandardFieldIndex.Contains(text))
			{
				return (int)this.m_MapStandardFieldIndex[text];
			}
			return -1;
		}

		private void AddEventField(NodeId eventTypeId, List<QualifiedName> browsePath, uint attributeId)
		{
			EventFieldConfiguration item = new EventFieldConfiguration(eventTypeId, browsePath, attributeId);
			this.m_StandardFields.Add(item);
			string text = "";
			for (int i = 0; i < browsePath.Count; i++)
			{
				text += browsePath[i].Name;
				if (i + 1 < browsePath.Count)
				{
					text += "/";
				}
			}
			this.m_MapStandardFieldIndex.Add(text, this.m_StandardFields.Count - 1);
		}

		private void AddEventField(NodeId eventTypeId, string browseName, uint attributeId)
		{
			List<QualifiedName> list = new List<QualifiedName>();
			if (browseName.Length != 0)
			{
				list.Add(browseName);
			}
			this.AddEventField(eventTypeId, list, attributeId);
		}
	}
}
